Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Refactor attachment upload into a service #1547

Merged
merged 5 commits into from
Apr 7, 2021

Conversation

frankchn
Copy link
Contributor

@frankchn frankchn commented Apr 4, 2021

Problem

Part of the set of pull requests that addresses #149

Solution

Refactor upload attachments to its own attachments service.

@frankchn frankchn requested a review from liangyuanruo April 4, 2021 03:41
Copy link
Contributor

@mantariksh mantariksh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for this, the controller is much cleaner now! in addition to the suggestions in the comments, could you also help with the following:

  1. add generic type arguments to the RequestHandler type for handleEncryptedSubmission. this is because when we don't supply generic type arguments, req.body is typed as any, which means we lack type safety in the controller. you can look at handleEmailSubmission for an example, and you can make use of the type EncryptSubmissionBody which is already defined in encrypt-submission.types.ts. I think the attachments key in EncryptSubmissionBody might be typed wrongly because it's missing the field ID, so you may have to fix that.
  2. avoid using res.locals within the controller, as everything in res.locals is typed as any by default as well. we can just use local variables within the controller.

src/app/modules/attachment/attachment.service.ts Outdated Show resolved Hide resolved
src/app/modules/attachment/attachment.service.ts Outdated Show resolved Hide resolved
src/app/modules/attachment/attachment.service.ts Outdated Show resolved Hide resolved
src/app/modules/attachment/attachment.service.ts Outdated Show resolved Hide resolved
src/app/modules/attachment/attachment.service.ts Outdated Show resolved Hide resolved
src/app/modules/core/core.errors.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@mantariksh mantariksh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, at the v2/submissions/encrypt endpoint (where handleEncryptedSubmission is called), we are calling forms.formById an extra time - could you remove that pls?

@frankchn frankchn requested a review from mantariksh April 7, 2021 02:29
@frankchn
Copy link
Contributor Author

frankchn commented Apr 7, 2021

@mantariksh made changes based on your comments, PTAL again, thanks!

@mantariksh
Copy link
Contributor

@frankchn thanks for the latest changes! could you also help with the following please:

  1. add generic type arguments to the RequestHandler type for handleEncryptedSubmission. this is because when we don't supply generic type arguments, req.body is typed as any, which means we lack type safety in the controller. you can look at handleEmailSubmission for an example, and you can make use of the type EncryptSubmissionBody which is already defined in encrypt-submission.types.ts. I think the attachments key in EncryptSubmissionBody might be typed wrongly because it's missing the field ID, so you may have to fix that.
  2. avoid using res.locals within the controller, as everything in res.locals is typed as any by default as well. we can just use local variables within the controller.
  3. at the v2/submissions/encrypt endpoint (where handleEncryptedSubmission is called), we are calling forms.formById an extra time - could you remove that pls?

@frankchn
Copy link
Contributor Author

frankchn commented Apr 7, 2021

@mantariksh Should I do this in another PR? The other refactorings are not really part of this PR and I don't really think should be rolled into this?

Copy link
Contributor

@mantariksh mantariksh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankchn sure, we can incorporate those changes in another PR. the code looks good other than a minor point on logging as well as merge conflicts (which should be easy to resolve).

@frankchn frankchn requested a review from mantariksh April 7, 2021 03:17
Copy link
Contributor

@mantariksh mantariksh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm other than merge conflicts!

@frankchn frankchn merged commit 1c6bc68 into develop Apr 7, 2021
@karrui karrui deleted the frank-controllers-4 branch April 7, 2021 04:15
@karrui karrui mentioned this pull request Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants